//返回值为需不需要关闭窗口
function yesOperator(){
    var retValue=addData();
    return retValue;
}
function formValid() {
    $("#theform").validate({
        rules: {
            b_cleanCode: {
                required: true,
                isCode:true
            },
            b_cleanName: {
                required: true,
            },
            b_rowSort: {
                required: true,
                minlength: 1,
                isPositiveInteger: true
            }

        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        },
        errorElement: "span",
        errorClass: "errortips errortips-w200",
        success: 'valid',
        messages: {
            b_cleanCode: {
                required: " (必填)"
            },
            b_cleanName: {
                required: " (必填)"
            },
            b_rowSort:{
                isIntGteZero: "输入正整数"
            }
        },
    });
}

function updateLoad(){
    var params = $$.getQueryString();
    $$.ajax({
        url:"/rest/IotCleanBusiness/query",
        data : {
            id : params.rowId
        },
        success : function(data){
            $("#b_id").val(data.id);
            $("#b_cleanCode").val(data.cleanCode);

            $("#b_cleanName").val(data.cleanName);

            $("#b_status").val(data.status);

            $("#b_rowSort").val(data.rowSort);

            $("#b_dataZero").val(data.dataZero);

            $("#b_dataEdata").val(data.dataEdata);
            $("#b_remarks").val(data.remarks);


            $("#b_cleanCodeOld").val(data.cleanCode);

            var status=data.status;
            $("input[name^='b_status_']").each(function(){
                if($(this).val()==status){
                    this.checked='checked';
                }
            });

        }
    });



}
function validForm(){

    return $("#theform").valid();
}
function addData(){
    var param = {};
    var validFormRet;
    $$.form({
        async:false,
        able:function(){
            validFormRet=false;
        },
        checkForm: validForm,
        success: function () {
            validFormRet= true;
        }
    });
    return validFormRet;
}

$(function () {
    formValid();
    $("input[name^='b_status']").click(function(){
        $("#b_status").val($(this).val());
    });
});
jQuery.validator.addMethod("isCode", function(value, element) {

    var cleanCodeOld=$("#b_cleanCodeOld").val();
    var cleanCode=$("#b_cleanCode").val();
    if(cleanCodeOld==cleanCode){
       return true;
    }else{

        var args={};
        args.c_cleanCode_1=$("#b_cleanCode").val();
        args.page=0;
        args.pageSize=5;
        args.isPage=1;


        var exists;
        $$.ajax({
            url: "/bootstrap/basegrid/IotCleanBusiness/list",
            async:false,
            data: args,
            success: function (data) {
                if(data.length && data.length>0){
                    exists=true;
                }else{
                    exists=false;
                }
            }
        });
        if(exists){
            $(element).data('error-msg','编码不能重复！');
            return false;
        }
        return true;
    }

}, function(params, element) {
    return $(element).data('error-msg');
});